from django.contrib.auth.models import User
from rest_framework import serializers
from .models import Course


class UserSerializer(serializers.Serializer):
    class Meta:
        model = User
        fields = '__all__'


class CourseSerializer(serializers.ModelSerializer):
    teacher = serializers.ReadOnlyField(source='teacher.username')

    class Meta:
        model = Course
        fields = "__all__"


# class CourseSerializer(serializers.HyperlinkedModelSerializer):
#     teacher = serializers.ReadOnlyField(source='teacher.username')
#
#     class Meta:
#         model = Course
#         # url是默认值，可在setting.py中设置URL_FIELD_NAME中使全局生效
#         # fields = ['id', 'url', 'name', 'introduction', 'teacher', 'price']
